package pl.qsoft.db.storedProc.statement;

import java.util.HashMap;
import java.util.Map;

import pl.qsoft.db.exception.StoredProcedureDefinitionException;

import static pl.qsoft.db.annotation.StoredProcedureDefinition.Vendor;;

/**
 * Factory returning a specific implementation of {@link StatementBuilder} given a vendor value
 * @author Wojciech Kudla
 */
public class StatementBuilderFactory {
	
	/**
	 * Map of Vendor -> StatementBuilder pairs
	 */
	private static Map<Vendor, StatementBuilder> builders = new HashMap<Vendor, StatementBuilder>();

	static {
		builders.put(Vendor.ORACLE, new OracleStatementBuilder());
	}
	
	
	/**
	 * Obtains a proper {@link StatementBuilder} for the given {@link Vendor}
	 * @param vendor Vendor
	 * @return StatementBuilder implementation
	 */
	public static StatementBuilder getStatementBuilder(Vendor vendor) {
		StatementBuilder statementBuilder = builders.get(vendor);
		if (statementBuilder == null) throw new StoredProcedureDefinitionException("No statement builder registered for vendor " + vendor);
		return statementBuilder;
	}
}
